package com.gec.anan.driver.service.impl;

import com.gec.anan.common.execption.AnanException;
import com.gec.anan.common.result.Result;
import com.gec.anan.common.result.ResultCodeEnum;
import com.gec.anan.driver.client.CosFeignClient;
import com.gec.anan.driver.service.CosService;
import com.gec.anan.model.vo.driver.CosUploadVo;
import com.gec.anan.model.vo.driver.DriverLoginVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class CosServiceImpl implements CosService {
    @Autowired
    private CosFeignClient client;

    @Override
    public CosUploadVo upload(MultipartFile multipartFile, String path) {
        Result<CosUploadVo> result = client.uploadVoResult(multipartFile, path);
        if(result==null){
            throw new AnanException(result.getCode(), result.getMessage());
        }
        if(result.getData()==null){
            throw new AnanException(ResultCodeEnum.DATA_ERROR);
        }
        return result.getData();
    }

    @Override
    public CosUploadVo uploadFile(MultipartFile multipartFile, String path) {
        Result<CosUploadVo> result = client.uploadVoResult(multipartFile, path);
        if(result==null){
            throw new AnanException(result.getCode(), result.getMessage());
        }
        if(result.getData()==null){
            throw new AnanException(ResultCodeEnum.DATA_ERROR);
        }
        return result.getData();
    }
}
